<?php

/**
 * NOTICE OF LICENSE
 *
 * THIS SOURCE FILE IS PART OF EVEBIT'S PRIVATE PROJECT.
 * 
 * DO NOT USE THIS FILE IN OTHER PLACE.
 *
 * @package   App_Sample
 * @author    Cheng Wei <berlios.o@gmail.com>
 * @version   $$Id: PrepareLayout.php 130 2011-03-18 03:10:02Z cheng.wei $$
 * @copyright Copyright (c) 2008 Evebit Inc. China (http://www.evebit.com)
 */

/**
 * Prepare layout for a page
 * 
 * @package   App_Sample
 * @author    Cheng Wei <berlios.o@gmail.com>
 * @version   $$Id: PrepareLayout.php 130 2011-03-18 03:10:02Z cheng.wei $$
 */
class Evebit_View_Helper_PrepareLayout extends Zend_View_Helper_Abstract {
	
	/**
	 * Prepare blocks by placehodler and partial
	 */
	public function prepareLayout() {
		$view = $this->view;
		
		$scope = Evebit_Application::app()->getScope();
		$file = RP . "/application/layouts/$scope.xml";
		
		if (is_file($file)) {
			$config = new Zend_Config_Xml($file);
			$config = $config->toArray();
			foreach ($config as $key => $block) {
				if (isset($block['placeholder']) && isset($block['template'])) {
					$template = $block['template'];
					try {
						$view->placeholder($block['placeholder'])->append(
							$view->partial($template, "blocks"));
					} catch (Exception $e) {
						$log = Evebit_Application::app()->getLog();
						if ($log) {
							$log->err($e);
						}
						trigger_error("View error in '$block[template]', " . $e->getMessage(), 
							E_USER_WARNING);
					}
				}
			}
		}
	}
}